﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ServiceModel;
using KerriganDataContract.Vehicule;
using KerriganDataContract;

namespace KerriganService.DAC
{
    public static class TypeVehicleDAC
    {
        public static List<TypeVehicleDC> GetListTypeVehicle()
        {
            List<TypeVehicleDC> entities = new List<TypeVehicleDC>();

            try
            {
                using(KerriganDBEntities db = new KerriganDBEntities())
                {
                    entities = CopyListEntitiesToListBos(db.TTypeVehicles.ToList());
                }
                
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }

            return entities;
        }
        
        public static TTypeVehicle CopyBoToEntity(TypeVehicleDC bo)
        {
            TTypeVehicle entity = new TTypeVehicle();

            try
            {
                entity.IdTypeVehicle = bo.IdTypeVehicle;
                entity.Name = bo.Name;
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }

            return entity;
        }

        public static TypeVehicleDC CopyEntityToBo(TTypeVehicle entity)
        {
            TypeVehicleDC bo = new TypeVehicleDC();

            try
            {
                bo.IdTypeVehicle = entity.IdTypeVehicle;
                bo.Name = entity.Name;
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }

            return bo;
        }

        public static List<TypeVehicleDC> CopyListEntitiesToListBos(List<TTypeVehicle> entities)
        {
            List<TypeVehicleDC> bo = new List<TypeVehicleDC>();

            try
            {
                foreach (TTypeVehicle entity in entities)
                {
                    bo.Add(CopyEntityToBo(entity));
                }
                return bo;
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }
    }
}